package com.jayanslow.lighting.server.parser;

import com.jayanslow.lighting.server.clients.Client;
import com.jayanslow.lighting.server.dmx.DmxController;

public class CommandParser {
	public enum TypeCommand {
		DMX (0x00), NET (0xD0);
		private TypeCommand(int s) { this.code = (short) s; }
		private final short code;
		public short getCode() { return code; }
		public static TypeCommand valueOf(short s) { 
			s = (short) (s & 0xF0);
			for (TypeCommand c : TypeCommand.values()) { if (c.getCode() == s) return c; }
			return null;
		}
	}
	
	public static short[] startParse(DmxController d, Client client, short[] ss) {
		if (ss.length == 0) return new short[0];
		TypeCommand cmd = TypeCommand.valueOf(ss[0]);
		switch (cmd) {
			case DMX:
				return (new DmxParser()).startParse(d, ss);
			case NET:
				return (new NetParser()).startParse(client, ss);
			default:
				return Errors.COMMAND.getArray();
		}
	}
}
